
package urnoted;
import java.awt.Color;

public class Staff {
    private static int MAX_NOTES = 8;      // 8 notes are stored
    private static int MAX_COLS_NOTES = 2; // 2 possible columns of notes
    private Note[][] mNotes;
    //private Clef mClef;

    /* Pre-conditions: None
     * Post-conditions: Initialize all then notes in a staff for all columns.
     */
    public Staff() {
        mNotes = new Note[MAX_NOTES][MAX_COLS_NOTES];
        for(int i = 0; i < MAX_NOTES; i++) {
            for(int j = 0; j < MAX_COLS_NOTES; j++) {
                mNotes[i][j] = new Note(i, Color.BLACK, false);
            }
        }
    }

    /* Pre-condition: note_val corresponds to a correct note value (0-7).
     * Post-conditions: staff is cleared of everything except main note
     * supplied as argument note_val. The note will be of color black.
     */
    public void setMainNote(int note_val) {
        clear();
        mNotes[note_val][0].setVisible(true);
        mNotes[note_val][0].setColor(Color.BLACK);
    }

    /* Pre-conditions: note_val corresponds to a correct note value (0-7).
     * Post-conditions: If note_val is the main note displayed, then change
     * the Note corresponding to note_val to the color green. If note_val is
     * not the note displayed, then change the Note corresponding to note_val
     * red and then pop up the note the user played in the second column by
     * changing the corresponding note_val visibility.
     *
     */
    public void keyPressed(int note_val) {
        if( mNotes[note_val][0].getVisible() == true ) {
            mNotes[note_val][0].setColor(Color.GREEN);
        }
        else {
            mNotes[note_val][0].setColor(Color.RED);
            mNotes[note_val][1].setColor(Color.GREEN);
            mNotes[note_val][1].setVisible(true);
        }
    }

    /* Pre-condition: none.
     * Post-condition: Clear the staff of all notes.
     */
    public void clear() {
        for(int i = 0; i < MAX_NOTES; i++) {
            for(int j = 0; j < MAX_COLS_NOTES; j++) {
                mNotes[i][j].setVisible(false);
            }
        }
    }
}